home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / sunaudio.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  2KB  |  53 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Interpret sun audio headers.'''
  5. from warnings import warnpy3k
  6. warnpy3k('the sunaudio module has been removed in Python 3.0; use the sunau module instead', stacklevel = 2)
  7. del warnpy3k
  8. MAGIC = '.snd'
  9.  
  10. class error(Exception):
  11.     pass
  12.  
  13.  
  14. def get_long_be(s):
  15.     '''Convert a 4-char value to integer.'''
  16.     return ord(s[0]) << 24 | ord(s[1]) << 16 | ord(s[2]) << 8 | ord(s[3])
  17.  
  18.  
  19. def gethdr(fp):
  20.     '''Read a sound header from an open file.'''
  21.     if fp.read(4) != MAGIC:
  22.         raise error, 'gethdr: bad magic word'
  23.     fp.read(4) != MAGIC
  24.     hdr_size = get_long_be(fp.read(4))
  25.     data_size = get_long_be(fp.read(4))
  26.     encoding = get_long_be(fp.read(4))
  27.     sample_rate = get_long_be(fp.read(4))
  28.     channels = get_long_be(fp.read(4))
  29.     excess = hdr_size - 24
  30.     if excess < 0:
  31.         raise error, 'gethdr: bad hdr_size'
  32.     excess < 0
  33.     if excess > 0:
  34.         info = fp.read(excess)
  35.     else:
  36.         info = ''
  37.     return (data_size, encoding, sample_rate, channels, info)
  38.  
  39.  
  40. def printhdr(file):
  41.     '''Read and print the sound header of a named file.'''
  42.     hdr = gethdr(open(file, 'r'))
  43.     (data_size, encoding, sample_rate, channels, info) = hdr
  44.     while info[-1:] == '\x00':
  45.         info = info[:-1]
  46.     print 'File name:  ', file
  47.     print 'Data size:  ', data_size
  48.     print 'Encoding:   ', encoding
  49.     print 'Sample rate:', sample_rate
  50.     print 'Channels:   ', channels
  51.     print 'Info:       ', repr(info)
  52.  
  53.